package org.jbit.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.jbit.bean.User;
import org.jbit.dao.BaseDao;

public class loginDao
{
	private Connection conn;

	private PreparedStatement ps;

	private ResultSet rs;
	 
	
	public String getUserType(String userName)
	{
		String type = null;
		String sql=null;
		sql="select type from userInfo where userName=?";	
try {
			
			conn = BaseDao.getConnection();
			ps = conn.prepareStatement(sql);
			ps.setString(1, userName);
			rs = ps.executeQuery();
			
			while (rs.next()) {
				type=rs.getString("type").trim();
			}
		}

		
		catch (Exception e) {
			e.printStackTrace();
		}

		
		finally {
			BaseDao.closeAll(rs, ps, conn);
		}
				
		return type;
	}
	
	

	
	public boolean checkUser(User user)
	{
		String sql = null;
		boolean flag = false;
		sql="select * from userInfo where userName=? and password=? and type=?";
		try {
					
					conn = BaseDao.getConnection();
					ps = conn.prepareStatement(sql);
					ps.setString(1,user.getUserName());
					ps.setString(2,user.getPassword());
					ps.setString(3,user.getType());
					rs = ps.executeQuery();
					

			while (rs.next()) {
				flag = true;
			}
		}

		catch (Exception e) {
			e.printStackTrace();
		}

		finally {
			BaseDao.closeAll(rs, ps, conn);
		}
		return flag;
	}
}

